package com.cjm;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @ClassName InnerClient
 * @Description TODO  内网服务器
 * @Author cjm
 * @Date 2020/8/4 15:08
 * @Version 1.0
 **/
public class InnerClient {

    public static void main(String[] args) throws IOException {

        int port = 9050;

        String host = "192.168.15.170";

        // 创建一个套接字并将其连接到指定端口号
        Socket socket = new Socket(host, port);

        DataInputStream dataIn = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));

        DataOutputStream dataOut = new DataOutputStream(
                new BufferedOutputStream(socket.getOutputStream()));

        boolean flag = false;

        while (!flag) {

            // TODO 发送E7服务网页给穿透软件

            System.out.println("******与穿透软件建立链接******");
            PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
            pw.println("E7");
            pw.flush();

            int status = dataIn.readInt();

            System.out.println("穿透服务器返回的状态为: " + status);

            // 获取到的状态码如果是200的话 进行发送数据
            if (status == 200) {
                System.out.println("******发送E7网页链接******");
                dataOut.writeChars("http://192.168.15.170:60009/");
                dataOut.flush();
                // 发送完毕
                flag = true;
            }
        }

        socket.close();
    }
}
